home *** CD-ROM | disk | FTP | other *** search
/ Best of www.BestZips.com (Collector's Edition) / Best of WWW.BESTZIPS.COM Collector's Edition (JCSM Shareware) (JCS Marketing).ISO / prgtools / tn2.zip / SIEVE.T < prev    next >
Text File  |  1996-11-15  |  802b  |  58 lines

  1. %
  2. % "sieve.t" uses the sieve of Eratosthenes to identify
  3. % prime numbers in the range 1..N.
  4. % This method originated in the 3rd century B.C.
  5. %
  6. %   Sample program for the T Interpreter by:
  7. %
  8. %   Stephen R. Schmitt
  9. %   962 Depot Road
  10. %   Boxborough, MA 01719
  11. %
  12.  
  13. const N : int := 5000
  14. var a : array[N] of boolean
  15.  
  16. program
  17.  
  18.     var i, j : int 
  19.  
  20.     init_a
  21.  
  22.     put "working "
  23.  
  24.     for i := 2...floor( N/2 ) do
  25.  
  26.         for j := 2...floor( N/i ) do
  27.  
  28.             a[i*j-1] := false
  29.  
  30.         end for
  31.  
  32.     end for
  33.  
  34.     put ""  
  35.  
  36.     for i := 1 ... N do
  37.  
  38.         if a[i-1] then
  39.  
  40.             put i : 10
  41.  
  42.         end if
  43.  
  44.     end for
  45.  
  46. end program
  47.  
  48. procedure init_a
  49.  
  50.     var i : int
  51.  
  52.     for i := 1 ... N do
  53.  
  54.         a[i-1] := true
  55.  
  56.     end for
  57.  
  58. end procedure